package com.core.cloudcommon.config;

import com.core.cloudcommon.trace.TraceInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author =====Lqj=====
 * @className TraceConfig
 * @description 链路追踪配置类
 * @create 2024/12/17 10:30
 **/
@Slf4j
@Configuration
public class TraceConfig implements WebMvcConfigurer {

    @Autowired
    private TraceInterceptor traceInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(traceInterceptor)
                .addPathPatterns("/**") // 拦截所有请求
                .excludePathPatterns(
                        "/error",           // 排除错误页面
                        "/favicon.ico",     // 排除图标
                        "/actuator/**",     // 排除监控端点
                        "/swagger-ui/**",   // 排除Swagger UI
                        "/swagger-resources/**", // 排除Swagger资源
                        "/v2/api-docs",     // 排除API文档
                        "/webjars/**",      // 排除静态资源
                        "/static/**",       // 排除静态资源
                        "/css/**",          // 排除CSS
                        "/js/**",           // 排除JS
                        "/images/**"        // 排除图片
                );
        
        log.info("链路追踪拦截器配置完成");
    }
}
